<?php

namespace Admin\Pages;

/**
 * Description of Index
 *
 * @author nofear
 */
class Products extends Page {

    private $objectEntity = 'Product';
    
    public function __construct() {
        parent::__construct();
        $this->view = new \System\Template('@admin/products.twig');
        $this->view->pageName = 'продукти';
    }
    
    public function index() {
        $QB = $this->EntityManager->createQueryBuilder();
        
        $products = $QB->select('o')
                ->from($this->projectEntityNamespace . $this->objectEntity, 'o')
                ->orderBy('o.id', 'DESC')
                ->getQuery()
                ->getResult();
                
        $Session = $this->getSession();
        if ( $Session->have('message') ) {
            $this->view->message = $Session->getMessage();
            $Session->removeMessage();
        }
        
        $this->view->products = $products;
    }

}
